home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / GoodBye / JohnKennedy / February96.lha / MASTERCLASS / AREXX / REXXARC.LHA / KillBak.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-02-01  |  2.1 KB  |  114 lines

  1. /* 
  2.     Search for file names
  3.     ending in #?bak, and then
  4.     delete them if necessary.
  5.          © John Kennedy
  6. */
  7.  
  8. address command /* Use AmigaDOS */
  9.  
  10. /* First, generate list of files & sizes */
  11.  
  12. Say "Making list of all files in current directory...."
  13.  
  14. 'list lformat "%p%n %l" all files > t:templist'
  15.  
  16.  
  17. /* Now, search for those ending in .bak */
  18.  
  19. Say "Adding up file sizes.."
  20.  
  21. infile='infile'
  22. outfile='outfile'
  23.  
  24. total_size=0
  25. number=0
  26.  
  27. call open(outfile,'t:report','w')
  28. call open(infile,"t:templist",'r')
  29.  
  30. do while ~eof(infile)
  31.     data=readln(infile)
  32.     if data~=''  then do
  33.         parse var data namepath " " size
  34.         if size='empty' then size=0
  35.         test=right(namepath,4)
  36.         if (test='.bak') then do
  37.             total_size=total_size+size
  38.             number=number+1
  39.             call writeln(outfile,namepath)
  40.         end
  41.     end
  42. end
  43. call close(infile)
  44. call close(outfile)
  45.  
  46. /* Process the files if required */
  47.  
  48. say "Number of backup files:" number
  49. say "Drive space taken up:  " total_size
  50. say
  51.  
  52. if number~=0 then call ProcessFiles()
  53.  
  54. /* All done! */
  55.  
  56. 'delete "t:report" quiet'
  57. 'delete "t:templist" quiet'
  58.  
  59. say "Finished."
  60. exit
  61.  
  62.  
  63.  
  64.  
  65. ProcessFiles:
  66.  
  67.     answer=''
  68.     do while (answer~="D" & answer~="C")
  69.         say "[D]elete files or [C]ancel?"
  70.         parse pull answer
  71.         answer=upper(answer)
  72.     end
  73.  
  74.     select
  75.         when answer='D' then call DeleteFiles()
  76.         when answer='C' then return
  77.     end
  78.  
  79.     return
  80.  
  81.  
  82. DeleteFiles:
  83.     
  84.     answer=''
  85.     confirm='Y'
  86.     do while (answer~="A" & answer~="C")
  87.         say "Delete [A]ll or [C]onfirm each one?"
  88.         parse pull answer
  89.         answer=upper(answer)
  90.     end
  91.  
  92.     call open(infile,"t:report",'r')
  93.     do n=1 to number
  94.         file=readln(infile)
  95.         data='delete '||d2c(34)||file||d2c(34)
  96.  
  97.  
  98.         if (answer="C") then 
  99.         do
  100.             confirm=''
  101.             do while (confirm~="Y" & confirm~="N" & confirm~="Q")
  102.             say "Delete " || file || " [Y]es, [N]o, [Q]uit?"
  103.             parse pull confirm
  104.             confirm=upper(confirm)
  105.             end
  106.         end
  107.         
  108.         if (confirm="Y") then interpret(data)
  109.         if (confirm="Q") then leave
  110.  
  111.     end
  112.     call close(infile)
  113.     return
  114.